package com.itheima.controller;

import com.itheima.mapper.NursingProjectMapper;
import com.itheima.pojo.NursingPage;
import com.itheima.pojo.NursingProject;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.server.NursingProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;
    @Autowired
    private NursingProjectMapper nursingProjectMapper;
    @GetMapping("/nursing")
    public Result list(NursingPage nursingPage){
        PageResult<NursingProject> pageResult=nursingProjectService.getlist(nursingPage);
        return Result.success(pageResult);
    }
    @PostMapping("/nursing/add")
    public Result add(@RequestBody NursingProject nursingProject){
        return Result.success(nursingProjectMapper.insert(nursingProject));
    }
    @GetMapping("/nursing/{id}")
    public Result getid(@PathVariable Integer id){
        return Result.success(nursingProjectMapper.selectById(id));
    }
    @PutMapping("/nursing")
    public Result update(@RequestBody NursingProject nursingProject){
        return Result.success(nursingProjectMapper.updateById(nursingProject));
    }
    @DeleteMapping("/nursing")
    public Result delete(@RequestParam Integer id){
        // 使用逻辑删除，将 deletelogic 字段设置为 1
        nursingProjectMapper.deleteById(id);
        return Result.success("删除成功");
    }
    @GetMapping("/nursing/all/list")
    public Result getAll() {
        List<NursingProject> list = nursingProjectService.getAll();
        return Result.success(list);
    }

}
